package backend.project.gym_management.service.impl;

import backend.project.gym_management.mapper.UploadFileMapper;
import backend.project.gym_management.pojo.entity.CourseImg;
import backend.project.gym_management.pojo.entity.EAvatar;
import backend.project.gym_management.service.UploadFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UploadFileServiceImpl implements UploadFileService {
    @Autowired
    private UploadFileMapper uploadFileMapper;
    @Override
    public int insertEAvatar(EAvatar avatar) throws Exception {
        var result = uploadFileMapper.insertEAvatar(avatar);
        if (result==0) throw new Exception("上传员工头像失败");
        return result;
    }

    @Override
    public EAvatar selectEAvatar(Long eid) throws Exception {
        return uploadFileMapper.selectEAvatarByEid(eid);
    }

    @Override
    public int deleteEAvatar(Long eid) throws Exception {
        var result = uploadFileMapper.deleteEAvatarByEid(eid);
        if (result==0) throw new Exception("删除员工头像失败");
        return result;
    }

    @Override
    public int insertCourseImg(CourseImg courseImg) throws Exception {
        var result = uploadFileMapper.insertCourseImg(courseImg);
        if(result==0) throw new Exception("上传课程图片失败");
        return result;
    }

    @Override
    public CourseImg selectCourseImg(Long cid) throws Exception {
        return uploadFileMapper.selectCourseImgByCid(cid);
    }

    @Override
    public int deleteCourseImg(Long cid) throws Exception {
        var result = uploadFileMapper.deleteCourseImgByCid(cid);
        if(result==0) throw new Exception("删除课程图片失败");
        return result;
    }
}
